package com.gitee.melin.bee.core.jdbc.parser;

public abstract class AbstractURLParser implements ConnectionURLParser {

    /**
     * Fetch the index range that database host and port from connection url.
     *
     * @return index range that database hosts.
     */
    protected abstract URLLocation fetchDatabaseHostsIndexRange(final String url);

    /**
     * Fetch the index range that database name from connection url.
     *
     * @return index range that database name.
     */
    protected abstract URLLocation fetchDatabaseNameIndexRange(final String url);

    /**
     * Fetch database name from connection url.
     *
     * @return database name.
     */
    protected String fetchDatabaseNameFromURL(String url) {
        URLLocation hostsLocation = fetchDatabaseNameIndexRange(url);
        return url.substring(hostsLocation.startIndex(), hostsLocation.endIndex());
    }
}
